package com.googlecode.entity_dao.core.cto.server;

import com.googlecode.entity_dao.core.criteria.AssociationPath;
import com.googlecode.entity_dao.core.criteria.NestedPropertyCriteria;
import com.googlecode.entity_dao.core.criteria.NestedPropertyCriterion;
import com.googlecode.entity_dao.core.cto.client.FilterAndSortCriteria;

/**
 * Generic persistent entity criteria transfer object mapping supporting a nested property of the target persistent
 * entity.
 * 
 * @see NestedPropertyMappingGroup
 * @see NestedPropertyCriterion
 * 
 * @author vojtech.szocs
 */
public abstract class NestedPropertyMapping {

    private final String propertyId;

    private final AssociationPath associationPath;
    private final String targetPropertyName;

    /**
     * Creates a new property mapping.
     * 
     * @param propertyId Symbolic persistent entity property identifier.
     * @param associationPath {@link AssociationPath} which points to the given property of the target persistent
     *            entity.
     * @param targetPropertyName Name of the target property of the given persistent entity.
     */
    public NestedPropertyMapping(String propertyId, AssociationPath associationPath, String targetPropertyName) {
        this.associationPath = associationPath;
        this.targetPropertyName = targetPropertyName;
        this.propertyId = propertyId;
    }

    /**
     * @return Symbolic persistent entity property identifier.
     */
    public String getPropertyId() {
        return propertyId;
    }

    /**
     * @return Name of the target property of the given persistent entity.
     */
    public String getTargetPropertyName() {
        return targetPropertyName;
    }

    /**
     * @return {@link AssociationPath} which points to the given property of the target persistent entity.
     */
    public AssociationPath getAssociationPath() {
        return associationPath;
    }

    /**
     * Applies query constraints defined by the <tt>clientSideCriteria</tt> to the <tt>serverSideCriteria</tt> according
     * to the property mapping implementation.
     * 
     * @param clientSideCriteria Client-side persistent entity criteria representation.
     * @param serverSideCriteria {@link NestedPropertyCriteria} instance to update.
     */
    public abstract void apply(FilterAndSortCriteria clientSideCriteria, NestedPropertyCriteria serverSideCriteria);

}
